package cn.edu.neusoft.zengweidong707.neufood.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import cn.edu.neusoft.zengweidong707.neufood.R;
import cn.edu.neusoft.zengweidong707.neufood.bean.IsSuccessBean;
import cn.edu.neusoft.zengweidong707.neufood.listener.ZwdListener;
import cn.edu.neusoft.zengweidong707.neufood.model.UserModel;

public class InsertCommentActivity extends BaseActivity {
    private EditText et_content;
    private Button btn_submit;
    private Button btn_back;
    private UserModel model;
    private ZwdListener<IsSuccessBean> listener;

    @Override
    void initView() {
        setLayout_file(R.layout.activity_insert_comment);
        et_content = (EditText) findViewById(R.id.et_content);
        btn_submit = (Button) findViewById(R.id.btn_submit);
        btn_back = (Button) findViewById(R.id.btn_back);
    }

    @Override
    void initEvent() {
        listener = new ZwdListener<IsSuccessBean>() {
            @Override
            public void onResponse(IsSuccessBean l) {
                if("1".equals(l.getSuccess()))
                {
                    showToast("评论成功");
                    finish();
                }
                else
                {
                    showToast("评论失败");
                    finish();
                }
            }

            @Override
            public void onFail(String msg) {
                showToast(msg);
            }
        };

        btn_submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = getIntent().getExtras();
                int orderId = bundle.getInt("orderid");
                String content = et_content.getText().toString();
                model = new UserModel();
                model.insertCommentByOrderid(orderId, content, listener);
            }
        });

        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }

    @Override
    void initData() {

    }
}
